/**
* eCommerce Application Sample for J2EE Training 
* @author Fabienne Boyer - july 2000
* @author Didier Donsez - november 2002  
*/

package miagetest.client.shell;

import miagetest.client.interfaces.ShellContext;
import javax.naming.NamingException;
import miagetest.client.commands.CategorieCommandImpl;
import miagetest.client.commands.CommandeCommandImpl;
import miagetest.client.commands.ClientCommandImpl;
import miagetest.client.commands.HelpCommandImpl;
import miagetest.client.commands.ProduitCommandImpl;
import miagetest.client.commands.SimpleQuitCommandImpl;

public class ShellMain extends ShellAbstract
{
	public static void main(String args[]) {
		// Start shell thread.
		new ShellMain(args).run();
	}

	public ShellMain(String args[]){
		
            out=System.out;
            err=System.err;

            if(!parseArgs(args)) stop();

            ShellContext context=getContext();

            // Chargement de la liste des commandes disponibles
            addCommand(new ClientCommandImpl(context));
            addCommand(new ProduitCommandImpl(context));
            addCommand(new CategorieCommandImpl(context));
            addCommand(new CommandeCommandImpl(context));
            addCommand(new HelpCommandImpl(context));
            addCommand(new SimpleQuitCommandImpl(context));

            // put the EBs' homes in the context
            context.setVar(PROMPT,"->");
            context.setVar(BANNER,this.getBanner());

            out.println("Connexion au serveur...");
            try
            {
                context.setVar(GESTIONNAIRE, EJBConnect.getGestionnaire(serverName));
                out.println("Obtention de l'EJB correcte.");
            }
            catch(NamingException e)
            {
                out.println("Impossible d'obtenir l'EJB.");
            }
	}
	
        @Override
	public String getBanner(){
		StringBuffer sb=new StringBuffer();		
		sb.append("\n-------------------------------------------------"); 
		sb.append("\n| Generic Shell                                 |"); 
		sb.append("\n| Bienvenue sur le client lourd Miagetest       |");
                sb.append("\n|                                               |");
		sb.append("\n-------------------------------------------------");
                sb.append("\nCommande 'help' pour l'aide.");
		return sb.toString();
	}

}
